package com.skywolf.chem.quartz;

import com.skywolf.chem.riding.mapper.InfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by pei_pei on 2020/9/7.
 */
@Slf4j
@Component
public class TimeTaskDemo {

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    @Autowired
    InfoMapper infoMapper;

    /**
     * 清空每周数据
     */
    @Scheduled(cron="0 5 0 ? * MON")
    public void weekTask(){
        String srartTime = format.format(new Date());
        log.info("TimeTaskDemo.weekTask time:{}",srartTime);
        srartTime = srartTime+" 00:00:00";
        infoMapper.updateRindIngInitWeek(srartTime);
    }


    /**
     * 清空每日数据
     */
    @Scheduled(cron="0 1 0 * * ? ")
    public void dayTask(){
        String srartTime = format.format(new Date());
        log.info("TimeTaskDemo.dayTask time:{}",srartTime);
        srartTime = srartTime+" 00:00:00";
        infoMapper.updateRindIngInitDay(srartTime);
    }
}
